/** @file fattime.c
 *  @brif get RTC time and convert it into fattime
 */
#include "stm32f2xx_rtc.h"
#include "integer.h"


DWORD get_fattime(void)
{
    RTC_TimeTypeDef RTC_TimeStruct;
    RTC_DateTypeDef RTC_DateStruct;
    DWORD time;
    short TY, TM, TD, THH, TMM, TSS;

    RTC_GetDate(RTC_Format_BIN, &RTC_DateStruct);
    RTC_GetTime(RTC_Format_BIN, &RTC_TimeStruct);

    TY = RTC_DateStruct.RTC_Year-80;	//year from 1980;(0-127)
    TM = RTC_DateStruct.RTC_Month;//month(1-12)
    TD = RTC_DateStruct.RTC_Date;//(1~31)
    THH = RTC_TimeStruct.RTC_Hours;//(0-23)
    TMM = RTC_TimeStruct.RTC_Minutes;//(0-59)
    TSS = RTC_TimeStruct.RTC_Seconds;//(0-29, in 2 seconds)

    time = (TY<<25) + (TM<<21) + (TD<<16) + (THH<<11) +(TMM<<5) + (TSS>>1);
}
